<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Created by JetBrains PhpStorm.
 * User: Johannes
 * Date: 2012-09-20
 * Time: 22:42
 * To change this template use File | Settings | File Templates.
 */
class base extends CI_Controller {
    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     * 		http://example.com/index.php/welcome
     *	- or -
     * 		http://example.com/index.php/welcome/index
     *	- or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see http://codeigniter.com/user_guide/general/urls.html
     */

    protected function webbPath() {
        $ip = $_SERVER['REMOTE_ADDR'];
        if($ip == "127.0.0.1") {
            return "/powergym/webb/";
        }
        else {
            return "/webb/";
        }
    }

    protected function header() {
        $data['webb'] = $this->webbPath();
        $GLOBALS['menu'] = $this->display_children(0, 1);
        $this->load->vars($GLOBALS);
        $this->load->view('header', $data);
    }

    protected function footer() {
        $data['webb'] = $this->webbPath();
        $this->load->view('footer', $data);
    }

    protected function carousel() {
        $data['webb'] = $this->webbPath();
        $this->load->view('carousel', $data);
    }

    protected function slider() {
        $data['webb'] = $this->webbPath();
        $this->load->view('slider', $data);
    }
    
    protected function adminHeader() {
        if(!isset($_SESSION['username'])) {
            redirect('/index.php/admin/loginView');
        }
        $data['webb'] = $this->webbPath();
        $this->load->view('admin/header', $data);
    }
    
    protected function adminFooter() {
        $data['webb'] = $this->webbPath();
        $this->load->view('admin/footer', $data);
    }
    
    public function display_children($parent, $level) {
        $result = $this->commonmodel->getMenu($parent);
        return $result;
        
        /*echo "<ul id='main_menu'>";
        foreach($result as $key) {
            if ($key->Count > 0) {
                echo "<li><a href='" . $key->link . "'>" . $key->label . "</a>";
                    $this->display_children($key->id, $level + 1);
                    echo "</li>";
            } elseif ($key->Count==0) {
                echo "<li><a href='" . $key->link . "'>" . $key->label . "</a></li>";
            } else;
        }
        echo "</ul>";*/
    }
}
